package day_7;

import java.util.Scanner;

public class ques1 {
    public static void main(String[]args){
        Scanner scan=new Scanner(System.in);
        int N=scan.nextInt();
        if(N==1){
            System.out.println(0);
            return;
        }
        int leftFib=0,rightFib=1,preIndex=0,index=0;
        boolean flag=true;
        while(flag){
            preIndex=index;
            index=leftFib+rightFib;
            if(N==index){
                System.out.println(N);
                return;
            }
            if(index>N){
                rightFib=index;
                leftFib=preIndex;
                break;
            }
            leftFib=rightFib;
            rightFib=index;

        }

        int a=rightFib-N>N-leftFib?N-leftFib:rightFib-N;
        System.out.println(a);
    }
}
